package com.yoda.mall.admin.controller;

import com.yoda.mall.admin.service.FlashService;
import com.yoda.mall.model.dto.CouponDto;
import com.yoda.mall.model.entity.sms.Coupon;
import com.yoda.mall.model.entity.sms.FlashPromotion;
import com.yoda.mall.model.vo.CouponVo;
import com.yoda.mall.model.vo.PageResult;
import com.yoda.mall.model.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/flash")
public class FlashController {
    @Autowired
    private FlashService flashService;
    //添加活动
    @PostMapping("create")
    public R createFlash(@RequestBody FlashPromotion flashPromotion){
        flashService.createFlash(flashPromotion);
        return R.success();
    }

    //删除活动
    @PostMapping("delete/{id}")
    public R deleteFlash(@PathVariable Long id){
        flashService.deleteFlash(id);
        return R.success();
    }

    //根据活动名称分页查询
    @GetMapping("list")
    public R flashList(String keyword,Integer pageNum,Integer pageSize){
        PageResult<FlashPromotion> pageResult = flashService.flashListPage(keyword,pageNum,pageSize);
        return R.success(pageResult);
    }

    //修改上下线状态
    @PostMapping("update/status/{id}")
    public R updateFlashPromotionStatus(Integer status,@PathVariable Long id){
        flashService.updateFlashPromotionStatus(id,status);
        return R.success();
    }

    //编辑活动
    @PostMapping("update/{id}")
    public R updateFlashPromotion(@RequestBody FlashPromotion flashPromotion,@PathVariable Long id){
        flashService.updateFlashPromotion(id,flashPromotion);
        return R.success();
    }

    //获取活动详情
    @GetMapping("{id}")
    public R getFlashPromotion(@PathVariable Long id){
        FlashPromotion flashPromotion = flashService.getFlashPromotion(id);
        return R.success(flashPromotion);
    }
}
